package org.agpsoft.simpledatareceiver;

import org.agpsoft.datareceiverinfrastructure.builder.IDataReceiverBuilder;
import org.agpsoft.datareceiverinfrastructure.builder.IDataReceiverMainHandler;
import org.agpsoft.datareceiverinfrastructure.datasource.IDataAccessor;
import org.agpsoft.datareceiverinfrastructure.exception.DataReceiverBuildException;
import org.agpsoft.datareceiverinfrastructure.exception.DataReceiverNULLObjectException;

public class SimpleBuilder implements IDataReceiverBuilder {

	@Override
	public IDataReceiverMainHandler build() throws DataReceiverBuildException {
		SimpleFacade facade = new SimpleFacade();
		
		try {
			IDataAccessor accessor = new SimpleDataAccessor();
			facade.setDataAccessor( accessor );
			
			SimpleDataTransmitter transmitter = new SimpleDataTransmitter();
			facade.setDataTransmitter( transmitter );
			
			SimpleDecodedDataRecorder decodedrecorder = new SimpleDecodedDataRecorder();
			facade.setDecodedDataRecorder( decodedrecorder );
			
			SimpleRawDataRecorder rawrecorder = new SimpleRawDataRecorder();
			facade.setRawDataRecorder( rawrecorder );
			
			accessor.setDataProcessor( facade );
			
			return new SimpleHandler( facade );
		} catch (DataReceiverNULLObjectException e) {
			throw new DataReceiverBuildException();
		}
	}

}
